package com.hkbigdata.sybx.controller;

import com.hkbigdata.sybx.bean.ContactUs;
import com.hkbigdata.sybx.service.ContactUsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuanbo
 * @creat 2025-05-29-19:48
 * @see 2194550857@qq.com
 */
@RestController
@RequestMapping("/api/contactUs")
public class ContactUsController {
    @Autowired
    private ContactUsService contactUsService;
    @PostMapping("/insert")
    public Map<String, Object> contactUsInsert(@RequestBody ContactUs contactUs){
        boolean b = contactUsService.ContactUsInsert(contactUs);
        Map<String, Object> response = new HashMap<>();
        response.put("success", b );
        return response;
    }
    @DeleteMapping("/deleteById/{id}")
    public Map<String, Object> deleteContactUsById(@PathVariable String id) {
        boolean result = contactUsService.deleteContactUsById(id);
        Map<String, Object> response = new HashMap<>();
        response.put("success", result);
        return response;
    }

    @DeleteMapping("/deleteByUserId/{userId}")
    public Map<String, Object> deleteContactUsByUserId(@PathVariable String userId) {
        boolean result = contactUsService.deleteContactUsByUserId(userId);
        Map<String, Object> response = new HashMap<>();
        response.put("success", result);
        return response;
    }

    @PutMapping("/update")
    public Map<String, Object> updateContactUs(@RequestBody ContactUs contactUs) {
        boolean result = contactUsService.updateContactUs(contactUs);
        Map<String, Object> response = new HashMap<>();
        response.put("success", result);
        return response;
    }

    @GetMapping("/getById/{id}")
    public Map<String, Object> getContactUsById(@PathVariable String id) {
        ContactUs contactUs = contactUsService.getContactUsById(id);
        Map<String, Object> response = new HashMap<>();
        response.put("data", contactUs);
        response.put("success", contactUs != null);
        return response;
    }

    @GetMapping("/getByUserId/{userId}")
    public Map<String, Object> getContactUsByUserId(@PathVariable String userId) {
        List<ContactUs> contactUsList = contactUsService.getContactUsByUserId(userId);
        Map<String, Object> response = new HashMap<>();
        response.put("data", contactUsList);
        response.put("success", true);
        return response;
    }

    @GetMapping("/list")
    public Map<String, Object> getAllContactUs() {
        List<ContactUs> contactUsList = contactUsService.getAllContactUs();
        Map<String, Object> response = new HashMap<>();
        response.put("data", contactUsList);
        response.put("success", true);
        return response;
    }
}